<template>
  <div class="px-4 h-full overflow-hidden">
    <div class="flex justify-between items-center py-2">
      <a-input-search v-model:value="searchKey" class="w-64" placeholder="姓名/助记码/床位号" @search="getData" />
      <div class="w-64 flex items-center justify-end">
        <a-button type="primary" @click=";(open = true), (rowData = {})">入区登记</a-button>
        <BaseExport type="住院" name="待入区" code="000177" class="ml-2" :search-params="{ status: store.tabsKey, bqbh: store.areaCode, pyjm: searchKey }"
          >导出</BaseExport
        >
      </div>
    </div>
    <BaseTable column-code="000177" :scroll="{ x: 2300 }" :data-source="tableData" fill :loading="loading">
      <template #bodyCell="{ column, record, index }">
        <template v-if="column.dataIndex === 'xh'">
          {{ index + 1 }}
        </template>
        <template v-if="column.dataIndex === 'action'">
          <a-button size="small" type="link" @click="onClickRow(record)"> 入区登记 </a-button>
          <a-button v-if="!record.inpTransferZone" size="small" type="link" @click="onClickWard(record)"> 更换病区 </a-button>
        </template>
      </template>
    </BaseTable>
    <EnterModal v-model:open="open" :row-data="rowData" @success="getData" />
    <ReplaceWard v-model:open="openWard" :data="rowData" @success="getData" />
  </div>
</template>
<script setup>
import { ref } from 'vue'
import BaseTable from '@/components/BaseTable'
import useStore from '../../store'
import EnterModal from '../component/EnterModal.vue'
import ReplaceWard from './ReplaceWard.vue'

const store = useStore()
const searchKey = ref('')
const open = ref(false)
const openWard = ref(false)
const rowData = ref({})

const { loading, tableData, getData } = useTable({
  url: '/inp/zydj/getInpRecordList',
  immediate: true,
  pagination: false,
  formatParams: () => {
    return {
      status: store.tabsKey,
      bqbh: store.areaCode,
      pyjm: searchKey.value
    }
  }
})

const onClickRow = (row) => {
  rowData.value = row
  open.value = true
}

// 更换病区
const onClickWard = (row) => {
  rowData.value = row
  openWard.value = true
}
</script>
